<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
$startt = (float) array_sum(explode(' ',microtime()));

$hostname = 'localhost';
$username = 'root';
$password = 'root';

$db = null;
try {
    $db = new PDO("mysql:host=$hostname;dbname=wikipedia", $username, $password);
    echo 'Connected to database';

    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);

    $sql = "Select * from articles";
    $result = $db->query($sql);
    $i = 1;

    $fp = fopen("/home/neozilon/wikipedia/importar.txt","w");
    foreach ($result as $row) {
        $article = utf8_encode($row["content"]);
        $title = utf8_encode($row["title"]);

        fwrite($fp, $title . PHP_EOL);
        fwrite($fp, '--ENDTITLE--' . PHP_EOL);
        fwrite($fp, $article . PHP_EOL);
        fwrite($fp, '--ENDPAGE--' . PHP_EOL);

    }
    fclose($fp);
}catch (PDOException $e) {
    echo $e->getMessage();
    echo "ERROR";
    exit();
}

$endt = (float) array_sum(explode(' ',microtime()));
echo "\n ***************************** \n";
echo "Processing time: ". sprintf("%.4f", ($endt-$startt))." seconds";
echo "\n ***************************** \n";


?>
